/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package viewer;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.awt.Window;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import main.Main;

/**
 * SplashScreen, will show for secondsToShow seconds, then will make the next JFrame visible. 
 * Typical usage:<br>
 * <b>
 * JFrame initFrame = new JFrame();<br>
 * initFrame.setSize(new Dimension(500,500));<br>
 * //other configurations for initFrame<br>
 * new Splash(initFrame);//(do not call setVisible directly on initFrame, the Splash will do it.<br>
 * </b>
 * @author ywaki
 */
public class Splash extends JFrame {

    private String message = "Without music, life would be a mistake.";
    private ImageIcon image = new ImageIcon(getClass().getResource("/images/app-icon.png"));
    private int secondsToShow;
    private JFrame nextScreen;

    
    /**
     * Constructs the Splash Screen
     * @param nextScreen The JFrame to be shown after delay time of splashscreen is ended
     */
    public Splash(JFrame nextScreen){
        this.nextScreen = nextScreen;
        secondsToShow = 3;
        
        JPanel container = new JPanel(new BorderLayout(30, 30));
        container.add(new JLabel(image),BorderLayout.CENTER);
        JLabel lblMessage = new JLabel(message, SwingConstants.CENTER);
        lblMessage.setFont(new Font("Segoe Script", Font.PLAIN, 17));
        lblMessage.setVerticalAlignment(SwingConstants.BOTTOM);
        container.add(lblMessage,BorderLayout.PAGE_END);
        
        container.setBackground(Color.WHITE);
        this.add(container);
        setIconImage(new ImageIcon(getClass().getResource("/images/app-icon.png")).getImage());
        this.setSize(new Dimension(400, 270));
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        this.setUndecorated(true);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        
        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                Splash.this.dispose();
            }
        };
        Timer timer = new Timer();
        timer.schedule(task, 1000*secondsToShow);
    }

    @Override
    public void dispose() {
        super.dispose();
        nextScreen.setVisible(true);
    }
}
